package com.huawei.appgallery.search.ui;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.search.api.IHotWordFragmentProtocol;
import com.huawei.appgallery.search.ui.HotWordFragmentProtocol.Request;
import com.huawei.appgallery.search.ui.cardbean.HistorySearchCardBean;
import com.huawei.appgallery.search.ui.cardbean.HistoryToggleCardBean;
import com.huawei.appgallery.search.ui.cardbean.HotWordCardBean;
import com.huawei.appgallery.search.ui.widget.SearchCardListAdapter;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse.TabInfo;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import o.ccz;
import o.cdh;
import o.cfv;
import o.cha;
import o.chm;
import o.cia;
import o.cih;
import o.cil;
import o.cim.a;
import o.cuv;
import o.cuv.f;
import o.cve;
import o.cvn;
import o.cvo;
import o.cvt;
import o.dge.d;
import o.dgh;
import o.dgp;
import o.dgy;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.epv;
import o.CollectCheck;

@FragmentDefine(alias = "HotWord", protocol = IHotWordFragmentProtocol.class)
public class HotWordFragment extends AppListFragment<HotWordFragmentProtocol> implements OnLayoutChangeListener {
    private int ʹ = ccz.ॱ();
    private b ˊ;
    private boolean ॱॱ = false;
    private boolean ᐝ;
    private HotWordFragmentProtocol ﹳ;
    private cvn ﾞ;

    public void ˏ(Bundle bundle) {
        super.ˏ(bundle);
    }

    public void ᐝʼ() {
        super.ᐝʼ();
        this.ﹳ = (HotWordFragmentProtocol) ˆ();
        Request request = this.ﹳ == null ? null : (Request) this.ﹳ.ॱ();
        if (request != null) {
            this.ॱॱ = request.ˍ();
            this.ʼˊ = request.ˊ();
        }
        this.ʹ = cdh.ˎ(ॱˋ());
    }

    public void ॱॱ(BaseDetailResponse<?> baseDetailResponse) {
        if (baseDetailResponse != null && ᐝॱ(baseDetailResponse.ˊᐝ())) {
            ˋ(ˏ(baseDetailResponse.ˎ(), baseDetailResponse.ˋˊ()));
        }
    }

    public cha ॱʿ() {
        return new cve(ॱˋ(), ʽॱ(), this.ᐝʽ, new Request());
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View ˋ = super.ˋ(layoutInflater, viewGroup, bundle);
        if (this.ͺˎ != null) {
            this.ᐝ = true;
            this.ﾞ = new cvn(this.ͺˎ, this);
            this.ͺˎ.addOnLayoutChangeListener(this.ﾞ);
        }
        return ˋ;
    }

    public void ˋ(int i) {
        super.ˋ(i);
        if (dof.ॱ(this.ʿॱ) && ˆ() != null) {
            Request request = (Request) ((HotWordFragmentProtocol) ˆ()).ॱ();
            if (request != null) {
                this.ʿॱ = request.ʻ();
                this.ʼˊ = request.ˊ();
            }
        }
        cvo.ˎ(this.ʼˊ, this.ʿॱ, this.ʹ);
    }

    public void ʽˊ() {
        super.ʽˊ();
        if (!this.ॱॱ) {
            dgh.ˋ("250701", ٴ());
        }
    }

    public cfv ˏ(String str, String str2, int i) {
        cfv ˎ = cfv.ˎ(str, "", this.ʹ, i);
        ˎ.setCacheID(ˎ.getCacheID());
        return ˎ;
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        if (this.ॱॱ) {
            ॱˋ(true);
        } else {
            super.ˋ(taskFragment, (List) list);
        }
    }

    public CardListAdapter ˎ(Context context, cia o_cia) {
        return new SearchCardListAdapter(context, o_cia);
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        chm.ॱ().ˋ();
    }

    public void ˏ(int i, cih o_cih) {
        if (i == 7) {
            String str;
            String str2 = "";
            if (o_cih.ˌ() instanceof HotWordCardBean) {
                HotWordCardBean hotWordCardBean = (HotWordCardBean) o_cih.ˌ();
                String ꜟ = hotWordCardBean.ꜟ();
                if (this.ˊ != null) {
                    if (this.ʼˊ == null || !this.ʼˊ.startsWith("hotsearchContent")) {
                        this.ˊ.ॱ(hotWordCardBean.ʽ(), hotWordCardBean.ꜟ(), false, false);
                    } else {
                        this.ˊ.ˏ(hotWordCardBean.ʽ(), hotWordCardBean.ꜟ(), false, false, "searchContent");
                    }
                }
                str = ꜟ;
            } else if (o_cih.ˌ() instanceof HistorySearchCardBean) {
                HistorySearchCardBean historySearchCardBean = (HistorySearchCardBean) o_cih.ˌ();
                if (this.ˊ != null) {
                    this.ˊ.ॱ(historySearchCardBean.ˊ(), "", false, false);
                }
                str = str2;
            } else {
                if (o_cih.ˌ() instanceof HistoryToggleCardBean) {
                    HistoryToggleCardBean historyToggleCardBean = (HistoryToggleCardBean) o_cih.ˌ();
                    if (this.ˊ != null) {
                        this.ˊ.ॱ(historyToggleCardBean.ॱ(), "", false, false);
                    }
                }
                str = str2;
            }
            ॱ(str);
            return;
        }
        if (i == 0) {
            if (o_cih.ˌ() instanceof BaseDistCardBean) {
                BaseDistCardBean baseDistCardBean = (BaseDistCardBean) o_cih.ˌ();
                dgh.onEvent(new d(ContentManager.getInstant().getContext(), f.ˋ).ˏ("02|" + baseDistCardBean.v_() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + baseDistCardBean.u_()).ˋ());
            }
        } else if (i == 200) {
            if (o_cih.ˌ() instanceof HotWordCardBean) {
                ((HotWordCardBean) o_cih.ˌ()).ˊ(String.valueOf(this.ʹ), this.ʼˊ);
                return;
            }
            return;
        }
        super.ˏ(i, o_cih);
    }

    private void ॱ(String str) {
        cil.ˋ(ॱˊ(), new a().ˊ(str).ˋ());
    }

    public void ॱ(Activity activity) {
        super.ॱ(activity);
        if (activity instanceof b) {
            this.ˊ = (b) activity;
        }
    }

    public void ˎ() {
        super.ˎ();
        this.ˊ = null;
        if (this.ͺˎ != null) {
            this.ͺˎ.removeOnLayoutChangeListener(this);
        }
    }

    public void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
        if (this.ﾞ != null && this.ﾞ.ॱ() && this.ᐝ) {
            this.ᐝ = false;
            ʻ(0);
        }
    }

    public void onScrollStateChanged(AbsListView absListView, int i) {
        super.onScrollStateChanged(absListView, i);
        if (1 == i && absListView.getId() == cuv.b.ʼ) {
            this.ᐝ = false;
            epv.ॱ(absListView.getContext(), (View) absListView);
        }
    }

    public void ˋᐝ() {
        boolean z = true;
        super.ˋᐝ();
        if (this.ﾞ != null) {
            this.ﾞ.ˊ(true);
        }
        if (this.ॱॱ || !this.ᵔ || (dof.ॱ(this.ʿॱ) && ꜝ() > 1)) {
            z = false;
        }
        if (z) {
            dgh.ˋ("250701", ٴ());
        }
    }

    private LinkedHashMap<String, String> ٴ() {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("URI", this.ʼˊ);
        linkedHashMap.put("serviceType", String.valueOf(this.ʹ));
        linkedHashMap.put("time", String.valueOf(System.currentTimeMillis() - this.ㆍॱ));
        return linkedHashMap;
    }

    public List<dgp> ˏ(List<TabInfo> list, String str) {
        if (CollectCheck.isEmpty((List) list) || list.size() <= 1) {
            return new ArrayList();
        }
        List<dgp> arrayList = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            TabInfo tabInfo = (TabInfo) list.get(i);
            if (tabInfo == null || TextUtils.isEmpty(tabInfo.ʼ()) || TextUtils.isEmpty(tabInfo.ᐝ())) {
                String str2 = "AppListFragment";
                StringBuilder append = new StringBuilder().append("tabInfo = ");
                String str3 = tabInfo == null ? HwAccountConstants.NULL : TextUtils.isEmpty(tabInfo.ʼ()) ? "tabId is empty" : "tabName is empty.";
                Logger.e(str2, append.append(str3).toString());
            } else {
                dgp o_dgp = new dgp();
                if (i == 0) {
                    o_dgp.ˋ(this.ʼˊ);
                } else {
                    o_dgp.ˋ(tabInfo.ʼ());
                }
                o_dgp.ॱ(tabInfo.ʼ().hashCode() + i);
                o_dgp.ˊ(tabInfo.ʽ());
                o_dgp.ˎ(tabInfo.ᐝ());
                o_dgp.ˊ(tabInfo.ʻ());
                o_dgp.ॱ(tabInfo.ͺ());
                o_dgp.ˎ(tabInfo.ॱˊ());
                o_dgp.ˏ(tabInfo.ॱॱ());
                o_dgp.ᐝ(str);
                o_dgp.ʼ(this.ॱㆍ);
                arrayList.add(o_dgp);
            }
        }
        return arrayList.size() <= 1 ? new ArrayList() : arrayList;
    }

    public void ˊʻ() {
        dgy.ˋ(this.ʼˊ);
    }

    public void ᐧॱ() {
    }

    public int י() {
        return ꜝ();
    }
}
